import { getToken,setToken, removeToken } from "@/utils/auth"

const state = {
  token: getToken()
}

const mutations = {
  setToken(state, token){
    state.token = token
    //同步到缓存
    setToken(token)

  },
  removeToken( ){
    //删除token
    state.token = null
    // 删除缓存区的token
    removeToken()
  }

}
const actions = {
  login( context, data){
    // const token = await login(data)
    // 返回一个token 123456
    context.commit('setToken', '123456')
  }
}

export default{
  
  namespaced: true,
  state,
  mutations,
  actions
}